package com.xq.sboot.amqp;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * 功能说明:Rabbit AMQP 入门教程Runner类.
 * <p>创建时间: 2019-01-02 16:48</p>
 *
 * @author 郭凯强
 * @version 1.0-SNAPSHOT
 */
public class RabbitAmqpTutorialsRunner implements CommandLineRunner {
    private final Logger logger = LoggerFactory.getLogger(RabbitAmqpTutorialsRunner.class);
    private final Marker marker = MarkerFactory.getMarker("RabbitAmqpTutorialsRunner");

    @Value("${tutorial.client.duration:0}")
    private int duration;
    @Autowired
    private ConfigurableApplicationContext applicationContext;

    /**
     * Callback used to run the bean.
     *
     * @param args incoming main method arguments
     * @throws Exception on error
     */
    @Override
    public void run(String... args) throws Exception {
        logger.debug(marker, "Ready ... running for {} s", this.duration);
        Thread.sleep(duration*1000L);
        this.applicationContext.close();
    }
}
